using System;
using System.Xml;
using System.Collections;

using Scenario.Modules.PCM.DataModel.ConfigurationManager.Entity;

namespace Scenario.Modules.PCM.DataModel.ConfigurationManager.Form
{
	//*********************************************************************
	//
	// Form Class
	//
	// The Form class represents the image of the graphic interface that works
	// width an entity and width some entityattributes that has some properties
	//
	//**********************************************************************
	public class XMLForm : bOS.XML.Data.XMLObject
	{
		/** PRIVATE FIELDS **/

		public const string MAIN_NODE	= "Form";

		private const string NAME_ATTRIBUTE		= "Name";
		private const string DESCRIPTION_NODE	= "Description";

		private string sName;
		private string sDescription;
		private XMLEntities vEntities;

		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Width simple form **/
		public XMLForm()
		{
			this.Init();
		}
		
		/** CONSTRUCTOR Width xml parsering**/
		public XMLForm(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		/** PROPERTIES **/

		public string Name 
		{
			get { return sName; }
			set { sName = value; }
		}

		public string Description 
		{
			get { return sDescription; }
			set { sDescription = value; }
		}

		public XMLEntities XMLEntities 
		{
			get { return vEntities; }
			set { vEntities = value; }
		}

		/** INSTANCE METHODS **/

		override public void Init()
		{
			sName = string.Empty;
			sDescription = string.Empty;

			vEntities = new XMLEntities ();
		}

		/** Parsering method for filling the form **/
		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;

			/** find the attributes situated on the root tag **/
			for ( int i=0; i<node2Parse.Attributes.Count;i++)
			{
				node = node2Parse.Attributes.Item(i);
				
				switch ( node.Name )
				{
					case XMLForm.NAME_ATTRIBUTE:
						sName = node.InnerText;
						break;
				}
			}

			/** find the sub tags witch contains from values **/
			for ( int i=0; i<node2Parse.ChildNodes.Count; i++)
			{
				node = node2Parse.ChildNodes[i];

				switch (node.Name) 
				{
					case XMLForm.DESCRIPTION_NODE:
						sDescription = node.InnerText;
						break;

					/** define the subcollection of the form By parsering the subtag entities **/
					case Entity.XMLEntities.MAIN_NODE:
						vEntities.Parse(node);
						break;
				} 
			}
		}

		override public bOS.XML.XMLNode GetXMLNode()
		{
			bOS.XML.XMLNode xmlNode = new bOS.XML.XMLNode(XMLForm.MAIN_NODE);
			xmlNode.AddAttribute ( new bOS.XML.XMLAttribute ( XMLForm.NAME_ATTRIBUTE, sName) );
			xmlNode.AddNode ( new bOS.XML.XMLNode (XMLForm.DESCRIPTION_NODE, sDescription) );

			xmlNode.AddNode ( vEntities.GetXMLNode() );
			
			return xmlNode;
		}

		/** STATIC METHODS **/

		/** no static methods **/
	}
}
